package com.gaoyi.crm.control;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.LinearLayoutCompat;

import com.gaoyi.crm.db.bean.TitleBean;

import java.util.List;

public class TitleView extends LinearLayoutCompat {

    private List<TitleBean> mData;
    private Context mContext;

    public void setData(List<TitleBean> data) {
        if (mData != null && !mData.isEmpty()) {
            removeAllViews();
        }
        this.mData = data;
        if (mData != null) {
            for (TitleBean bean : mData) {
                TextView tv = new TextView(mContext);
                tv.setText(bean.getTitle());
                tv.setGravity(Gravity.CENTER);
                tv.setLayoutParams(new LinearLayoutCompat.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT,bean.getWeight()));
                addView(tv);
            }
        }
    }

    public TitleView(@NonNull Context context) {
        super(context);
        init(context);
    }

    public TitleView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public TitleView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        mContext = context;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
